#!/bin/sh
echo "start"
#unityapp的路径
export untiy=/Applications/Unity/Unity.app/Contents/MacOS/Unity
#项目路径
export projectPath=/Users/pengfei.guo/project/app_match3_unity
#把所有=后面的参数取出来
for a in $*
do
	r=`echo $a | sed "s/--//g"`
	eval $r
done
#这里就可以拿到jenkins传递进来的参数了
echo "version = $version"
echo "appname = $appname"
export LOGIN_USER_NAME=pengfei.guo
#Unity3d项目打包后生成的APK路径
export UNITY3D_OUTPUT_PATH="/Users/${LOGIN_USER_NAME}/JenkinsProjects/AndroidOutput/"
#Apk包名（要和Unity3d项目内配置的一致）
export OLD_APK_NAME=${appname}.apk
export NEW_APK_NAME=${appname}_${BUILD_TIMESTAMP}_${BUILD_ID}.apk

echo "NEW_APK_NAME = $NEW_APK_NAME"

$untiy -quit -batchmode -projectPath $projectPath -logFile /tmp/logFile.log  -executeMethod BuildPackage.BuildForAndroid "$version" "$appname"


#重命名Apk包名
# mv ${UNITY3D_OUTPUT_PATH}${OLD_APK_NAME} ${UNITY3D_OUTPUT_PATH}${NEW_APK_NAME}